package cn.zjitc.service.impl;

import cn.zjitc.dao.AdminBorrowDao;
import cn.zjitc.entity.PageResult;
import cn.zjitc.entity.QueryPageBean;
import cn.zjitc.pojo.Borrow;
import cn.zjitc.pojo.History;
import cn.zjitc.service.AdminBorrowService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = AdminBorrowService.class)
@Transactional
public class AdminBorrowServiceImpl implements AdminBorrowService {
    @Autowired
    private AdminBorrowDao adminBorrowDao;

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();

        PageHelper.startPage(currentPage,pageSize);
        Page<Borrow> page = adminBorrowDao.findByCondition(queryString);
        long total = page.getTotal();
        List<Borrow> rows = page.getResult();
        return new PageResult(total,rows);
    }


    @Override
    public Integer findremainnum(Integer id) {
        return adminBorrowDao.findremainnum(id);
    }

    @Override
    public Integer findmaxnum(Integer id) {
        return adminBorrowDao.findmaxnum(id);
    }

    @Override
    public void edit(Borrow borrow) {
        adminBorrowDao.edit(borrow);
    }

    @Override
    public void editbooklist(Integer id) {
        adminBorrowDao.editbooklist(id);
    }

    @Override
    public void editHistory(History history) {
        adminBorrowDao.editHistory(history);
    }
}
